﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartWMS.Common.Extensions;
using SmartWMS.Common.ResponseOutput;
using SmartWMS.Domain.BasicsDatum;
using SmartWMS.Server.BasicsDatumServer.CarrierManagementService;
using SmartWMS.Server.BasicsDatumServer.CarrierManagementService.Dto;
using System.Collections.Generic;

namespace SmartWMS.API.Controllers.BasicsDatumMange
{
	/// <summary>
	/// 承运商管理控制器
	/// </summary>
	[Route("api/[controller]/[action]")]
	[ApiController]
	[ApiExplorerSettings(GroupName = "BasicsDatum")]
	public class CarrierManagementController : ControllerBase
	{
		private readonly ICarrierManagementService _carrierManagementService;

		public CarrierManagementController(ICarrierManagementService carrierManagementService)
		{
			_carrierManagementService = carrierManagementService;
		}

		/// <summary>
		/// 显示承运商信息
		/// </summary>
		/// <param name="dto"></param>
		/// <returns></returns>
		[HttpPost]
		public IActionResult GetCarrierManagementDtoAsync(SearchCarrierDto dto)
		{
			try
			{
				var pageObj =  _carrierManagementService.GetCarrierManagementDtoAsync(dto);
				return Ok(new
				{
					pageObj.Result.totalCount,
					pageObj.Result.pageCount,
					data = pageObj.Result.data
				});
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 添加承运商
		/// </summary>
		/// <param name="info">要添加的承运商表实体</param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<bool>> AddCarrierManagement(CarrierDto info)
		{
			try
			{
				var result = await _carrierManagementService.AddCarrierManagement(info);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 删除承运商管理
		/// </summary>
		/// <param name="info">要删除的承运商管理</param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<bool>> DelCarrierManagement(CarrierDto info)
		{
			try
			{
				var result = await _carrierManagementService.DelCarrierManagement(info);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 反填承运商管理
		/// </summary>
		/// <param name="id">要反填的承运商Id</param>
		/// <returns></returns>
		[HttpPost]
		public Response<CarrierDto> FilCarrierManagement(CarrierDto dto)
		{
			try
			{
				var result = _carrierManagementService.FilCarrierManagement(dto.Id);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 修改承运商管理
		/// </summary>
		/// <param name="info">要修改的承运商实体</param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<bool>> UpdCarrierManagement(CarrierDto info)
		{
			try
			{
				var result = await _carrierManagementService.UpdCarrierManagement(info);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 批量删除承运商
		/// </summary>
		/// <param name="dto"></param>
		/// <returns></returns>
		[HttpPost]
		public Task<Response<bool>> BatchCarrierManagement(CarrierDto dto)
		{
			try
			{
				var result = _carrierManagementService.BatchCarrierManagement(dto);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}
	}
}
